/**
 * LogCashFreezeService.java
 * Copyright(C) 1949++ 中华人民共和国
 * 深圳市盛开互联网金融顾问有限公司.
 * All rights reserved.
 * E-mail:server@skjr.net
 * SKDate:2017-11-16 17:28:58
 */
package com.huamao.zh.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.huamao.zh.base.PageWrapper;
import com.huamao.zh.constants.CashFreezeType;
import com.huamao.zh.mapper.LogCashFreezeMapper;
import com.huamao.zh.model.LogCashFreeze;
import com.huamao.zh.service.LogCashFreezeService;

@Service
@Transactional
public class LogCashFreezeServiceImpl implements LogCashFreezeService {

	@Autowired
	private LogCashFreezeMapper logCashFreezeMapper;

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogCashFreeze add(LogCashFreeze logCashFreeze) throws Exception {
		logCashFreezeMapper.add(logCashFreeze);
		return logCashFreeze;
	}

	/**
	 * 功能说明：记录流水内部方法 Author：spring Date：2017/11/20 15:50
	 */
	private LogCashFreeze getCashFreeze(CashFreezeType type, Integer fromId, Integer userId, String orderNo,
			BigDecimal preCash, BigDecimal cash, String remark) {
		LogCashFreeze logCashFreeze = new LogCashFreeze();
		logCashFreeze.setType(type.getCode());
		logCashFreeze.setFromId(fromId);
		logCashFreeze.setUserId(userId);
		logCashFreeze.setOrderNo(orderNo);
		logCashFreeze.setPreCash(preCash);
		logCashFreeze.setCash(cash);
		logCashFreeze.setRemark(remark);
		logCashFreeze.setDataFlag(1);
		logCashFreeze.setCreateTime(new Date());
		return logCashFreeze;
	}

	/**
	 * 功能说明：记录现金流水日志 -- 增加专用 Author：spring Date：2017/11/20 15:47
	 */
	@Override
	public LogCashFreeze sumCashFreeze(CashFreezeType type, Integer fromId, Integer userId, String orderNo,
			BigDecimal preCash, BigDecimal cash, String remark) throws Exception {
		LogCashFreeze cashFreeze = this.getCashFreeze(type, fromId, userId, orderNo, preCash, cash, remark);
		cashFreeze.setCashType(1);
		return this.add(cashFreeze);
	}

	@Override
	public LogCashFreeze subtractCashFreeze(CashFreezeType type, Integer fromId, Integer userId, String orderNo,
			BigDecimal preCash, BigDecimal cash, String remark) throws Exception {
		LogCashFreeze cashFreeze = this.getCashFreeze(type, fromId, userId, orderNo, preCash, cash, remark);
		cashFreeze.setCashType(0);
		return this.add(cashFreeze);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogCashFreeze addSelective(LogCashFreeze logCashFreeze) throws Exception {
		logCashFreezeMapper.addSelective(logCashFreeze);
		return logCashFreeze;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int delete(Map<String, Object> map) {
		return logCashFreezeMapper.delete(map);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int update(LogCashFreeze logCashFreeze) throws Exception {
		return logCashFreezeMapper.update(logCashFreeze);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int updateSelective(LogCashFreeze logCashFreeze) throws Exception {
		return logCashFreezeMapper.updateSelective(logCashFreeze);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogCashFreeze get(Integer id) {
		LogCashFreeze logCashFreeze = logCashFreezeMapper.get(id);
		return logCashFreeze;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public PageWrapper<LogCashFreeze> search(PageWrapper<LogCashFreeze> pageWrapper) {
		List<LogCashFreeze> logCashFreezes = logCashFreezeMapper.search(pageWrapper);
		pageWrapper.setList(logCashFreezes);
		return pageWrapper;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public List<LogCashFreeze> queryList(Map<String, Object> map) {
		return logCashFreezeMapper.queryList(map);
	}
}